﻿using System;
using System.Collections.Generic;
//
using PerceptiveMCAPI;
//
namespace PerceptiveMCAPI_Test
{
   public partial class get_listSubscribe : System.Web.UI.UserControl
   {
      // ---------------------------------------------------------------
      // used for listSubscribe, listUpdateMember
      // ---------------------------------------------------------------
      public ApiMethod method { get; set; }

      public string listId
      {
         get { return tbListId.Text.Trim(); }
         set { tbListId.Text = value; }
      }
      public string email_address
      {
         get { return tbEmail.Text.Trim(); }
         set { tbEmail.Text = value; }
      }
      public EnumValues.emailType email_type
      {
         get { return ApiHelper.GetEnumFromString<EnumValues.emailType>( ddlEMailType.SelectedItem.Text ); }
         set { ddlEMailType.SelectedValue = Convert.ToInt32( value ).ToString(); }
      }

      public bool double_optin
      {
         get { return cbDoubleOptin.Checked; }
         set { cbDoubleOptin.Checked = value; }
      }
      public bool replace_interests
      {
         get { return cbReplaceInterest.Checked; }
         set { cbReplaceInterest.Checked = value; }
      }
      public bool update_existing
      {
         get { return cbUpdateExisting.Checked; }
         set { cbUpdateExisting.Checked = value; }
      }
      public bool send_welcome
      {
         get { return cbSendWelcome.Checked; }
         set { cbSendWelcome.Checked = value; }
      }
      public Dictionary<string, object> merge_vars
      {
         get { return sub_MergeVars1.MergeVarsList; }
      }

      // -----------------------------------------------------
      public bool Setup()
      {
         this.Visible = true;
         lblSection.Text = method.section;
         lblMethod.Text = method.name;
         //
         ddlEMailType.DataSource = EnumValues.listEmailTypeValues();
         ddlEMailType.DataBind();
         //
         email_address = "";
         email_type = MCAPISettings.default_listSubscribe_email_type;
         double_optin = MCAPISettings.default_listSubscribe_double_optin;
         replace_interests = MCAPISettings.default_listSubscribe_replace_interests;
         update_existing = MCAPISettings.default_listSubscribe_update_existing;
         //
         cbDoubleOptin.Visible = true;
         cbReplaceInterest.Visible = true;
         cbUpdateExisting.Visible = true;
         cbSendWelcome.Visible = true;

         if ( method.name == "listSubscribe" )
         {
            send_welcome = MCAPISettings.default_listSubscribe_send_welcome;
         }
         else if ( method.name == "listUpdateMember" )
         {
            cbDoubleOptin.Visible = false;
            cbUpdateExisting.Visible = false;
            cbSendWelcome.Visible = false;
            email_type = EnumValues.emailType.NotSpecified;
         }
         return true;
      }
   }
}